<template>
  <canvas
    style="width: 200px; height: 200px"
    canvas-id="myQrcode"
    id="myQrcode"
    ref="foo"
  ></canvas>
</template>

<script>
import Taro from "@tarojs/taro";
import drawQrcode from "weapp-qrcode";

export default {
  name: "QRCode",
  props: {
    config: {
      type: Object,
      default: () => {
        return {
          width: 200,
          height: 200,
          canvasId: "myQrcode",
        };
      },
    },
    text: String,
  },
  mounted() {
    setTimeout(() => {
      this.initQrCode();
    }, 500);
  },
  methods: {
    initQrCode() {

      const res = Taro.getSystemInfoSync()
      const scale = res.screenWidth / 375;

      drawQrcode({
        ...this.config,
        width: 170 * scale,
        height: 170 * scale,
        text: this.text,
      });
    },
  },
};
</script>
